package web;

import pojo.SmbmsBill;
import pojo.SmbmsUser;
import service.SmbmsBillService;
import service.SmbmsUserService;
import service.impl.SmbmsBillServiceImpl;
import service.impl.SmbmsUserServiceImpl;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
@WebServlet(value = "/updateBillServlet")
public class UpdateBillServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
        this.doPost(req, resp);
    }
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
        SmbmsBill smbmsBill=new SmbmsBill();
        String ids=req.getParameter("id");
        System.out.println(ids);
        Long id=Long.parseLong(ids);
//给对象赋值，从界面获取
//订单编码
        String billcode=req.getParameter("billCode");
//商品名称
        String productname=req.getParameter("productName");

//商品单位
        String productunit=req.getParameter("productUnit");
        try {
//商品数量
            String productcount=req.getParameter("productCount");
//总金额
            String totalprice=req.getParameter("totalPrice");
//供应商(待编写)
            String providerId=req.getParameter("providerId");
            int providerid=Integer.parseInt(providerId);
//是否付款
            String isPayment=req.getParameter("isPayment");
            int ispayment=Integer.parseInt(isPayment);

            smbmsBill.setBillCode(billcode);
            smbmsBill.setProductName(productname);
            smbmsBill.setProductUnit(productunit);
            smbmsBill.setProductCount(productcount);
            smbmsBill.setTotalPrice(totalprice);
            smbmsBill.setProviderId(providerid);
            smbmsBill.setIsPayment(ispayment);
            smbmsBill.setId(id);
//调用业务层接口
            SmbmsBillService smbmsBillService=new SmbmsBillServiceImpl();
            int i = smbmsBillService.updateBill(smbmsBill);
            if(i>0){
//修改成功
                req.getRequestDispatcher("/BillListServlet").forward(req,resp);
            }else{
                resp.sendRedirect("BillUpdate.jsp");
            }
        } catch (ParseException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

